// src/components/FolderSelector.js
import React from 'react';
import { Button } from '@mui/material';

const FolderSelector = ({ onFolderSelected }) => {
  const selectFolder = async () => {
    try {
      const directoryHandle = await window.showDirectoryPicker();

      const systemFolders = ['Windows', 'System', 'Program Files', 'Applications'];
      if (systemFolders.includes(directoryHandle.name)) {
        alert('请选择一个非系统的文件夹进行整理。');
        return;
      }

      onFolderSelected(directoryHandle);
    } catch (error) {
      console.error('选择文件夹失败:', error);
      alert('选择文件夹时发生错误，请重试或选择其他文件夹。');
    }
  };

  return (
    <Button variant="contained" color="secondary" onClick={selectFolder}>
      选择要整理的文件夹
    </Button>
  );
};

export default FolderSelector;